﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using WordDocumentGenerator.Library;

namespace GPS.ENTITYS
{
    #region Export Word thông tin chi tiết
    public class CrudModelFORMDKH
    {
        [DisplayFormat(DataFormatString = "{0:0}", ApplyFormatInEditMode = true)]
        public decimal? STT { get; set; }
        public string KH_MA { get; set; }
        public string KH_DVGTVT_MA { get; set; }
        public string DVGTVT_TEN { get; set; }
        public string KH_TEN { get; set; }
        public string KH_HANGGPLX_MA { get; set; }
        public string KH_HANGDT_MA { get; set; }
        [DisplayFormat(DataFormatString = "{0:0}", ApplyFormatInEditMode = true)]
        public decimal KH_HANGDT_RANK { get; set; }
        public string KH_SOQDKG { get; set; }


        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public Nullable<System.DateTime> KH_NGAYQDKG { get; set; }

        public string KH_NGAYQDKG_TEXT {
           get
            {
                if (this.KH_NGAYQDKG != null)
                {
                    return this.KH_NGAYQDKG.Value.ToString("dd/MM/yyyy");
                }
                else
                    return string.Empty;
            }
           
        }


        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public Nullable<System.DateTime> KH_NGAYKG { get; set; }

        public string KH_NGAYKG_TEXT
        {
            get
            {
                if (this.KH_NGAYKG != null)
                {
                    return this.KH_NGAYKG.Value.ToString("dd/MM/yyyy");
                }
                else
                    return string.Empty;
            }

        }

        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public Nullable<System.DateTime> KH_NGAYBG { get; set; }

        public string KH_NGAYBG_TEXT
        {
            get
            {
                if (this.KH_NGAYBG != null)
                {
                    return this.KH_NGAYBG.Value.ToString("dd/MM/yyyy");
                }
                else
                    return string.Empty;
            }

        }

        public string KH_MUCTIEUDT { get; set; }

        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public Nullable<System.DateTime> KH_NGAYTHI { get; set; }

        public string KH_NGAYTHI_TEXT
        {
            get
            {
                if (this.KH_NGAYTHI != null)
                {
                    return this.KH_NGAYTHI.Value.ToString("dd/MM/yyyy");
                }
                else
                    return string.Empty;
            }

        }

        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public Nullable<System.DateTime> KH_NGAYSH { get; set; }

        public string KH_NGAYSH_TEXT
        {
            get
            {
                if (this.KH_NGAYSH != null)
                {
                    return this.KH_NGAYSH.Value.ToString("dd/MM/yyyy");
                }
                else
                    return string.Empty;
            }

        }

        [DisplayFormat(DataFormatString = "{0:0}", ApplyFormatInEditMode = true)]
        public Nullable<decimal> KH_TONGHV { get; set; }
        [DisplayFormat(DataFormatString = "{0:0}", ApplyFormatInEditMode = true)]
        public Nullable<decimal> KH_SOHVTOTNGHIEP { get; set; }
        [DisplayFormat(DataFormatString = "{0:0}", ApplyFormatInEditMode = true)]
        public Nullable<decimal> KH_SOHVDUOCCAPGPLX { get; set; }
        [DisplayFormat(DataFormatString = "{0:0}", ApplyFormatInEditMode = true)]
        public Nullable<decimal> KH_THOIGIANDT { get; set; }
        [DisplayFormat(DataFormatString = "{0:0}", ApplyFormatInEditMode = true)]
        public Nullable<decimal> KH_SONGAYONKIEMTRA { get; set; }
        [DisplayFormat(DataFormatString = "{0:0}", ApplyFormatInEditMode = true)]
        public Nullable<decimal> KH_SONGAYTHUCHOC { get; set; }
        [DisplayFormat(DataFormatString = "{0:0}", ApplyFormatInEditMode = true)]
        public Nullable<decimal> KH_SONGAYNGHILE { get; set; }
        [DisplayFormat(DataFormatString = "{0:0}", ApplyFormatInEditMode = true)]
        public Nullable<decimal> KH_TONGSONGAY { get; set; }
        public string KH_MOTA { get; set; }
        public string KH_ACTIVE { get; set; }
        [DisplayFormat(DataFormatString = "{0:0}", ApplyFormatInEditMode = true)]
        public Nullable<decimal> KH_TTXL_MA { get; set; }
        public Nullable<System.DateTime> KH_NGAYNHAP { get; set; }
        public string KH_NGUOINHAP { get; set; }
        public Nullable<System.DateTime> KH_NGAYSUA { get; set; }
        public string KH_NGUOISUA { get; set; }
    }


    public class EXPORTWORD_FORMDKH
    {
        public static byte[] EXPORT_FORMDKH(string templateFileName, object objSource, string docType)
        {
            DocumentGenerationInfo generationInfo = GetDocumentGenerationInfo(docType, "1.0", objSource, templateFileName, false);
            COMMON.ExportCore<CrudModelFORMDKH> docGenerator = new COMMON.ExportCore<CrudModelFORMDKH>(generationInfo);
            return docGenerator.GenerateDocument();
        }
        /// <summary>
        /// Gets the document generation info.
        /// </summary>
        /// <param name="docType">Type of the doc.</param>
        /// <param name="docVersion">The doc version.</param>
        /// <param name="dataContext">The data context.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="useDataBoundControls">if set to <c>true</c> [use data bound controls].</param>
        /// <returns></returns>
        private static DocumentGenerationInfo GetDocumentGenerationInfo(string docType, string docVersion, object dataContext, string fileName, bool useDataBoundControls)
        {
            DocumentGenerationInfo generationInfo = new DocumentGenerationInfo();
            generationInfo.Metadata = new DocumentMetadata
            {
                DocumentType = docType,
                DocumentVersion = docVersion
            };
            generationInfo.DataContext = dataContext;
            generationInfo.TemplateData = File.ReadAllBytes(fileName);
            generationInfo.IsDataBoundControls = useDataBoundControls;
            return generationInfo;
        }

    }
    #endregion
}
